package com.zwd.cases.common.constant;

/**
 * @Description 通用返回工具类
 * @Author zhengwd
 * @Date 2022/7/21 11:38
 **/
public class ResponseResult<T> {

    private int code;
    private String msg;
    private T data;

    /**
     * 返回 code message data 方法构造器
     * @param rc
     * @param data
     */
    public ResponseResult(ResponseCode rc, T data) {
        this.data = data;
        this.msg = rc.msg;
        this.code = rc.id;
    }

    /**
     * successful
     * @param data
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> success(T data){
        return new ResponseResult<T>(ResponseCode.SERVER_SUCCESS, data);
    }

    /**
     * error
     * @param data
     * @param <T>
     * @return
     */
    public static  <T> ResponseResult<T> error(T data){
        return new ResponseResult<T>(ResponseCode.SERVER_ERROR, data);
    }
}

